import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/config/enum/load_state.dart';
import 'package:flutter_changdian_football/pages/home/club_ranking/desc/club_ranking_details_controller.dart';
import 'package:flutter_changdian_football/widget/custom_button.dart';
import 'package:flutter_changdian_football/widget/default_page/custom_empty.dart';
import 'package:flutter_changdian_football/widget/dialog/application_info_dialog.dart';
import 'package:flutter_changdian_football/widget/extended_image_slide_widget.dart';
import 'package:flutter_changdian_football/widget/load_state/load_state_layout.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:flutter_changdian_football/widget/sheet/share_icon_sheet.dart';
import 'package:get/get.dart';
import 'package:get/route_manager.dart';

/// 俱乐部排行详情
class ClubRankingDetailsPage extends StatelessWidget {
  const ClubRankingDetailsPage({super.key, required this.clubId});

  final String clubId;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors:  [
              const Color(0xff49935E),
              const Color(0xff4EAE6B),
              const Color(0xff4EAE6B).withOpacity(0.4),
              const Color(0xff4EAE6B).withOpacity(0.3),
              const Color(0xff4EAE6B).withOpacity(0.2),
              const Color(0xff4EAE6B).withOpacity(0.1),
              const Color(0xff4EAE6B).withOpacity(0.1),
              const Color(0xff4EAE6B).withOpacity(0.1),
              const Color(0xff4EAE6B).withOpacity(0.1),
              const Color(0xff518361).withOpacity(0),
            ],
          ),
        ),
        child: GetBuilder<ClubRankingDetailsController>(
          init: ClubRankingDetailsController(clubId: clubId),
          builder: (clubRankingDetailsController) {
            return Stack(
              children: [
                LoadStateLayout(
                  state: clubRankingDetailsController.state,
                  empty: const CustomEmpty(
                    text: '暂无该俱乐部详情',
                  ),
                  success: SafeArea(
                    child: Column(
                      children: [
                        Expanded(
                          child: SingleChildScrollView(
                            padding: EdgeInsets.symmetric(horizontal: 17.w),
                            physics: const BouncingScrollPhysics(),
                            child: Center(
                              child: Column(
                                children: [
                                  SizedBox(height: 100.w,),
                            
                                  Stack(
                                    clipBehavior: Clip.none,
                                    alignment: Alignment.center,
                                    children: [
                                      Container(
                                        width: double.infinity,
                                        height: 150.w,
                                        decoration: BoxDecoration(
                                          color: Colors.white,
                                          borderRadius: BorderRadius.circular(12.r)
                                        ),
                                        padding: EdgeInsets.only(bottom: 12.w),
                                        child: Row(
                                          crossAxisAlignment: CrossAxisAlignment.end,
                                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                                          children: [
                                            _topAndBottomWidget(text: '竞技强度', value: '${clubRankingDetailsController.clubDetailModel?.clubSportsName ?? '-'}'),
                                            _topAndBottomWidget(text: '活跃度', value: '${clubRankingDetailsController.clubDetailModel?.liveness ?? '0'}'),
                                            _topAndBottomWidget(text: '人数', value: '${clubRankingDetailsController.clubDetailModel?.playerNum ?? '0'}'),
                                            _topAndBottomWidget(text: '比赛场次', value: '${clubRankingDetailsController.clubDetailModel?.matchCount ?? '0'}'),
                                          ],
                                        ),
                                      ),
                
                                      Positioned(
                                        top: -40.w,
                                        child: Column(
                                          children: [
                                            GestureDetector(
                                              behavior: HitTestBehavior.translucent,
                                              onTap: () {
                                                if (clubRankingDetailsController.clubDetailModel?.clubImage != null) {
                                                  Get.to(
                                                    ExtendedImageSlideWidget(
                                                      url: "${clubRankingDetailsController.clubDetailModel?.clubImage ?? ''}",
                                                    ),
                                                    opaque: false
                                                  );
                                                }
                                              },
                                              child: Container(
                                                width: 88.w,
                                                height: 88.w,
                                                decoration: BoxDecoration(
                                                  borderRadius: BorderRadius.circular(10.r),
                                                  color: Colors.white,
                                                  border: Border.all(
                                                    width: 2.w,
                                                    color: Colors.white
                                                  ),
                                                  boxShadow: const [
                                                    BoxShadow(
                                                      color: Color.fromRGBO(0, 0, 0, 0.0800),
                                                      offset: Offset(0, 2),
                                                      blurRadius: 4,
                                                    ),
                                                  ],
                                                ),
                                                child: ClipRRect(
                                                  borderRadius: BorderRadius.circular(10.r),
                                                  child: Image.network(clubRankingDetailsController.clubDetailModel?.clubImage ?? '', fit: BoxFit.fill, excludeFromSemantics: true, gaplessPlayback: true,)
                                                ),
                                              ),
                                            ),
                
                                            SizedBox(height: 5.w,),
                
                                            SizedBox(
                                              child: Text(clubRankingDetailsController.clubDetailModel?.clubName ?? '', style: TextStyle(fontSize: 16.sp, color: const Color(0xff333333), fontWeight: FontWeight.bold),),
                                            )
                                          ],
                                        )
                                      )
                                    ],
                                  ),
                
                                  SizedBox(height: 16.w,),
                
                                  Container(
                                    decoration: BoxDecoration(
                                      borderRadius: BorderRadius.circular(12.r),
                                      color: Colors.white
                                    ),
                                    padding: EdgeInsets.symmetric(vertical: 4.w),
                                    child: Column(
                                      children: [
                                        _leftAndRightWidget(text: '创始日', val: '${clubRankingDetailsController.clubDetailModel?.clubCreateTime ?? ''} ', icon: 'assets/images/img_list_da.png'),
                
                                        Container(
                                          width: double.infinity,
                                          height: 1.w,
                                          color: const Color(0xffF8FAF9 ),
                                        ),
                
                                        _leftAndRightWidget(text: '地址', val: '${clubRankingDetailsController.clubDetailModel?.clubAddress ?? ''}', icon: 'assets/images/img_list_dw03.png'),
                
                                        Container(
                                          width: double.infinity,
                                          height: 1.w,
                                          color: const Color(0xffF8FAF9 ),
                                        ),
                
                                        _leftAndRightWidget(text: '活跃场地', val: '${clubRankingDetailsController.clubDetailModel?.clubHomeCourtName ?? ''}', icon: 'assets/images/hycd.png'),
                
                                        Container(
                                          width: double.infinity,
                                          height: 1.w,
                                          color: const Color(0xffF8FAF9 ),
                                        ),
                
                                        _leftAndRightWidget(text: '俱乐部简介', val: '${clubRankingDetailsController.clubDetailModel?.clubProfile ?? ''}', icon: 'assets/images/img_list_jj.png'),
                                      ],
                                    ),
                                  )
                                ],
                              ),
                            ),
                          ),
                        ),

                        if (clubRankingDetailsController.clubDetailModel?.isJoinClub?.toUpperCase() == 'false'.toUpperCase()) ...[
                          Container(
                            padding: EdgeInsets.all(17.w),
                            child: CustomButton(
                              text: '申请加入',
                              onTap: () {
                                clubRankingDetailsController.messageController.clear();

                                ApplicationInfoDialog.show(
                                  Get.context!,
                                  controller: clubRankingDetailsController.messageController,
                                  cancelTap: () {
                                    Get.back();
                                  },
                                  confirmTap: () {
                                    clubRankingDetailsController.joinApply();
                                  }
                                );
                              },
                            ),
                          )
                        ]
                      ],
                    ),
                  ),
                ),

                SafeArea(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      IconButton(
                        onPressed: () {
                          Get.back();
                        }, 
                        icon: const Icon(Icons.arrow_back, color: Colors.white,)
                      ),

                      if (clubRankingDetailsController.state == LoadState.success) ...[
                        IconButton(
                          onPressed: () {
                            clubRankingDetailsController.getSharePage();
                          }, 
                          icon: SizedBox(
                            width: 22.w,
                            height: 22.w,
                            child: Image.asset('assets/images/share_qr.png', color: Colors.white,),
                          )
                        )
                      ]
                    ],
                  ),
                )
              ],
            );
          }
        ),
      ),
    );
  }


  _topAndBottomWidget({
    String value = '',
    String text = ''
  }) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        Text(
          value,
          style: TextStyle(fontSize: 18.sp, color: const Color(0xff499360), fontWeight: FontWeight.w500),
        ),
        SizedBox(height: 3.w,),
        Text(
          text,
          style: TextStyle(fontSize: 12.sp, color: const Color(0xff999999)),
        ),
      ],
    );
  }


  _leftAndRightWidget({
    String icon = '',
    String text = '',
    String val = ''
  }) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 17.w, vertical: 10.w),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            padding: EdgeInsets.only(top: 2.w),
            child: SizedBox(
              width: 16.w,
              height: 16.w,
              child: Image.asset(icon),
            ),
          ),

          SizedBox(width: 9.w,),

          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(
                  child: Text(text, style: TextStyle(fontSize: 16.sp, color: const Color(0xff323232), fontWeight: FontWeight.bold),),
                ),

                SizedBox(height: 7.w,),

                SizedBox(
                  child: Text(val, style: TextStyle(fontSize: 14.sp, color: const Color(0xff999999)),),
                )
              ],
            ),
          )
        ],
      ),
    );
  }

}